<?php
	session_start();

	require_once '../includes/Facebook/FacebookRequest.php';
	require_once '../includes/Facebook/FacebookSDKException.php';
	require_once '../includes/Facebook/FacebookRequestException.php';
	require_once '../includes/Facebook/FacebookSession.php';
	require_once '../includes/Facebook/FacebookRedirectLoginHelper.php';
	require_once '../includes/Facebook/FacebookResponse.php';
	require_once '../includes/Facebook/FacebookAuthorizationException.php';
	require_once '../includes/Facebook/GraphObject.php';
	require_once '../includes/Facebook/GraphUser.php';


	use Facebook\FacebookRequest;
	use Facebook\FacebookSession;
	use Facebook\FacebookRedirectLoginHelper;
	use Facebook\FacebookSDKException;
	use Facebook\FacebookRequestException;
	use Facebook\FacebookResponse;
	use Facebook\FacebookAuthorizationException;
	use Facebook\GraphObject;
	use Facebook\GraphUser;

?>
<?php
	FacebookSession::setDefaultApplication('670364983058320', 'c4347a6b3e70e7bae5b636454df2fa81');

	$helper = new FacebookRedirectLoginHelper('http://localhost/wewant1/sites/login.php');
	$loginUrl = $helper->getLoginUrl();
	// Use the login url on a link or button to redirect to Facebook for authentication
	try {
	  $session = $helper->getSessionFromRedirect();
	} catch(FacebookRequestException $ex) {
	  // When Facebook returns an error
		$ex->getMessage();

	} catch(\Exception $ex) {
	  // When validation fails or other local issues
		$ex->getMessage();
	}

	if ($session) {
	  // Logged in
		try {

			$request = new FacebookRequest($sesion,'GET','/me');
			$response = $request->execute();
			$me = $response->getGraphObject(GraphUser::className());
			echo $me->getName();

		} catch(FacebookRequestException $ex){
			$ex->getMessage();
		}
	} else{
		echo "you have to login Facebook<br/>";
		echo "<a href='{$loginUrl}'>Login Facebook</a>";

	}

?>